import { useAppStore } from 'src/stores/app-store';
import { RouteLocationNormalizedLoaded, Router } from 'vue-router';
import { getUrlParam } from 'src/boot/paramhandler';

export const useLoginHook = (router: Router, route: RouteLocationNormalizedLoaded) => {
  return {
    afterLoginHandler: () => {
      const { pageType, isAuth, token, userInfo } = useAppStore();
      if (pageType === 'download') {
        return router.replace({ path: '/down', query: route.query });
      }
      if (pageType == 'list') {
        return router.replace({ path: '/prodList', query: route.query });
      }
      // userInfo.authFlag
      if (isAuth && !!+userInfo.sourceFlag) {
        if (pageType === 'auth') {
          return router.push({ path: '/infoInput', query: route.query });
        }
        if (pageType === 'h5_auth_download') {
          return router.replace({ path: '/down', query: route.query });
        }
        if (pageType === 'h5_auth_list') {
          return router.replace({ path: '/prodList', query: route.query });
        }
      } else if (isAuth && !+userInfo.sourceFlag) {
        if (['auth', 'h5_auth_download', 'h5_auth_list'].includes(pageType)) {
          return router.push({ path: '/infoInput', query: route.query });
        }
      }
      return router.push({ path: '/realNameAuth', query: route.query });
    },
  };
};
